package com.hngates.architecture.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hngates.common.annotation.Log;
import com.hngates.common.enums.BusinessType;
import com.hngates.architecture.domain.ArcLabourSubCompany;
import com.hngates.architecture.service.IArcLabourSubCompanyService;
import com.hngates.common.core.controller.BaseController;
import com.hngates.common.core.domain.AjaxResult;
import com.hngates.common.utils.poi.ExcelUtil;
import com.hngates.common.core.page.TableDataInfo;

/**
 * 劳务分包单位Controller
 * 
 * @author jwhe
 * @date 2022-07-04
 */
@Controller
@RequestMapping("/architecture/labourSubCompany")
public class ArcLabourSubCompanyController extends BaseController
{
    private String prefix = "architecture/labourSubCompany";

    @Autowired
    private IArcLabourSubCompanyService arcLabourSubCompanyService;

    @RequiresPermissions("architecture:labourSubCompany:view")
    @GetMapping()
    public String labourSubCompany()
    {
        return prefix + "/labourSubCompany";
    }

    /**
     * 查询劳务分包单位列表
     */
    @RequiresPermissions("architecture:labourSubCompany:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ArcLabourSubCompany arcLabourSubCompany)
    {
        startPage();
        List<ArcLabourSubCompany> list = arcLabourSubCompanyService.selectArcLabourSubCompanyList(arcLabourSubCompany);
        return getDataTable(list);
    }

    /**
     * 导出劳务分包单位列表
     */
    @RequiresPermissions("architecture:labourSubCompany:export")
    @Log(title = "劳务分包单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ArcLabourSubCompany arcLabourSubCompany)
    {
        List<ArcLabourSubCompany> list = arcLabourSubCompanyService.selectArcLabourSubCompanyList(arcLabourSubCompany);
        ExcelUtil<ArcLabourSubCompany> util = new ExcelUtil<ArcLabourSubCompany>(ArcLabourSubCompany.class);
        return util.exportExcel(list, "劳务分包单位数据");
    }

    /**
     * 新增劳务分包单位
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存劳务分包单位
     */
    @RequiresPermissions("architecture:labourSubCompany:add")
    @Log(title = "劳务分包单位", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ArcLabourSubCompany arcLabourSubCompany)
    {
        return toAjax(arcLabourSubCompanyService.insertArcLabourSubCompany(arcLabourSubCompany));
    }

    /**
     * 修改劳务分包单位
     */
    @RequiresPermissions("architecture:labourSubCompany:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ArcLabourSubCompany arcLabourSubCompany = arcLabourSubCompanyService.selectArcLabourSubCompanyById(id);
        mmap.put("arcLabourSubCompany", arcLabourSubCompany);
        return prefix + "/edit";
    }

    /**
     * 修改保存劳务分包单位
     */
    @RequiresPermissions("architecture:labourSubCompany:edit")
    @Log(title = "劳务分包单位", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ArcLabourSubCompany arcLabourSubCompany)
    {
        return toAjax(arcLabourSubCompanyService.updateArcLabourSubCompany(arcLabourSubCompany));
    }

    /**
     * 删除劳务分包单位
     */
    @RequiresPermissions("architecture:labourSubCompany:remove")
    @Log(title = "劳务分包单位", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(arcLabourSubCompanyService.deleteArcLabourSubCompanyByIds(ids));
    }
}
